<%@ page language="java" pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@ include file="/commons/jsp/taglibs.jsp" %>
<%@taglib uri="http://www.framework.com/taglib" prefix="frame" %>
<head>
    <title>公共平台 </title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <!-- 样式文件的引入 -->
    <link href="${ctx}/commons/css/style.css" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/commons/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="${ctx}/commons/themes/icon.css">
    <!-- jqueryUI JS文件的引入 -->
    <script type="text/javascript" src="${ctx}/commons/js/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="${ctx}/commons/js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="${ctx}/commons/js/easyui-extends-validate.js"></script>
    <!-- jqueryUI国际化 -->
    <script type="text/javascript" src="${ctx}/commons/js/easyui-lang-zh_CN.js"></script>
    <!-- 开发使用的公用js方法 -->
    <script type="text/javascript" src="${ctx}/commons/js/common.js"></script>
    <!-- 开发国际化的引用，主要完成后台信息在前台提示的国际化，一定要放在最后 -->

    <script type="text/javascript" src="${ctx}/c2c/Public/Js/moment.min.js"></script>
    <script type="text/javascript" src="${ctx}/c2c/Public/Js/json2.js"></script>


    <script type="text/javascript">var ctx = '${ctx}';
    var actionExt = "action";
    var i18n = new Object();</script>
    <script src="${ctx}/commons/js/i18n/message_zh_CN.js" type="text/javascript"></script>
</head>

<body>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'north',border:false" style="padding: 4px;height: 80px;overflow: hidden;">
        <div class="easyui-panel" data-options="fit:true,border:true">
            <div class="queryContent">
                <form name="searchProjectsForm" id="searchProjectsForm" method="post" action="" style="display: none; ">
                    <table class="queryTable">
                        <tbody>
                        <tr>
                            <th>项目名称</th>
                            <td width="10%">
                                <input id="auctionName" class="easyui-validatebox" type="text" name="auctionName"
                                       maxlength="50"
                                       style="width:120px;height: 15px;"/>
                            </td>
                            <th>项目编号</th>
                            <td>
                                <input id="code" class="easyui-validatebox" type="text" name="code" maxlength="20"
                                       style="width:120px;height: 15px;"/>
                            </td>
                            <th>项目类型</th>
                            <td width="10%">
                                <select class="easyui-combobox" name="catagoryId" style="width:120px;;height: 25px;"
                                        data-options="">
                                    <option value="">--请选择--</option>
                                    <c:forEach items="${projectTypeList}" var="type">
                                        <option value="${type.id}">${type.name}</option>
                                    </c:forEach>
                                </select>
                            </td>
                            <!--
								<th >资金来源</th>
							<td>
							 	<select id="moneySource" style="width:120px" class="easyui-combobox" name="moneySource">
							 		<option value="">--请选择--</option>
									<c:forEach items="${frame:dictChildren('moneySource')}" var="type">
										<option value="${type.value}">${type.name}</option>
									</c:forEach>
								</select>
							</td>
							 -->
                            <th>状态</th>
                            <td>
                                <select id="status" style="width:120px;height: 25px;" class="easyui-combobox"
                                        name="status">
                                    <option value="">--请选择--</option>
                                    <c:forEach items="${frame:dictChildrenByRole('proj_status','bidder')}" var="type">
                                        <option value="${type.value}">${type.name}</option>
                                    </c:forEach>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <th>创建时间</th>
                            <td align="right" colspan="5">
                                <input id="startTime" class="easyui-datebox" type="text" name="startTime"
                                       data-options="validType:['dateTimeLessCompare[\'stopTime\']']" maxlength="20"
                                       style="width:120px;height: 25px;"/>-<input id="stopTime" class="easyui-datebox"
                                                                                  type="text"
                                                                                  data-options="validType:['dateTimeMoreCompare[\'startTime\']']"
                                                                                  name="stopTime" maxlength="20"
                                                                                  style="width:120px;height: 25px;"/>
                            </td>
                            <!--
                            <th>预算金额(元)</th>
                            <td>
                                 <input id="startMoney" class="easyui-validatebox" type="text" name="startMoney"  data-options="validType:['rangeLessCompare[\'endMoney\']']" maxlength="20" style="width:120px"/>-<input id="endMoney" class="easyui-validatebox" type="text"  data-options="validType:['rangeMoreCompare[\'startMoney\']']" name="endMoney" maxlength="20" style="width:120px"/>
                            </td>
                            -->
                            <th></th>
                            <td align="right" colspan="3">
                                <a href="javascript:void(0);" class="easyui-linkbutton" id="searchProjects"
                                   iconcls="icon-search" plain="true">查询</a>
                                <a href="javascript:void(0);" class="easyui-linkbutton" id="resetsearchProjects"
                                   iconcls="icon-reset" plain="true">清空</a>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </form>
            </div>
        </div>
    </div>
    <div data-options="region:'center',border:false" style="padding: 4px;">
        <table id="listProjectsTable" class="easyui-datagrid"
               data-options="singleSelect:false,toolbar:'#goodstb',method:'post',rownumbers:true,fit:true,fitColumns:true,border:true,
					pagination:true,multiSort:true,remoteSort:true,striped:true,
					url:'${ctx}/auction/business/list?roleId=bidder'" }>
            <thead>
            <tr>
                <th data-options="field:'auctionName',width:170,title:'项目名称',sortable:true" align="center"></th>
                <th data-options="field:'code',width:90,title:'项目编号',sortable:true" align="center"></th>
                <th data-options="field:'catagoryName',width:80,title:'项目类型',sortable:true" align="center"></th>
                <%--<th data-options="field:'auditable',width:80,title:'竞价发起人',sortable:true,formatter: function(value,row,index){if(value==true){return '公共资源交易中心';}else{{return '采购人';}}}" align="center"></th>--%>
                <th data-options="field:'ownerName',width:120,title:'产权人',sortable:true" align="center"></th>
                <th data-options="field:'auditName',width:100,title:'中心审核人',sortable:true" align="center"></th>
                <th data-options="field:'createTime',width:100,title:'创建时间',sortable:true" align="center"></th>
                <th data-options="field:'entryStart',width:100,title:'报名时间',sortable:true" align="center"></th>
                <th data-options="field:'auctionStart',width:80,title:'竞拍开始时间 ',sortable:true" align="center"></th>
                <th data-options="field:'statusName',width:80,title:'状态',sortable:true" align="center"></th>
                <th data-options="field:'operation',width:160,title:'操作'" align="center"></th>
            </tr>
            </thead>
        </table>

        <!----------------------- wei start --------------------->
        <!--导出Excel -->
        <input type="hidden" id="excel_error" value="${requestScope.excel_error }"/>
        <script type="text/javascript">
            //导出
            function excelexport() {
                $("form").attr("action", "${ctx}/business/projectmanage/export")
                $("form").submit();

                var val = $("#excel_error").val();
                if (val != "") {//不为空提示错误消息
                    $.messager.alert("操作提示", val, "error");
                }
            }

        </script>
        <!----------------------- wei end --------------------->
    </div>
</div>
<div id="bindPicDialog"></div>
<div id="selPicDialog"></div>
<div id="noCompetReasonDialog"></div>
</body>
<script type="text/javascript">
    //初始化表格对应的js对象
    var projectsParamObj;
    $(function () {
        //初始化表格对象数据
            projectsParamObj = new initAuctionParams(
            {
                paramObjName: 'projectsParamObj',//表格对应的实体对象名称，好区分多个表格情况下的对象
                tableId: 'listProjectsTable',
                addDataFormId: 'addProjectsDataForm',
                showDialogId: 'firstLevelDialog',
                searchID: 'searchProjects',
                resetSearchID: 'resetsearchProjects',
                searchFormID: 'searchProjectsForm',
                updateUrl: "${ctx}/business/projectmanage/input?projectId=",
                deleteUrl: '${ctx}/business/projectmanage/remove',
                addDialogWidth: 700,
                addDialogHeight: 520,
                ctx: '${ctx}',
                addDialogTitle: '投标信息',
                auctionInfoDialogId: 'auctionInfoDialog'
            });
        //初始化查询
        init(projectsParamObj);
        //setTimeout(function(){
        //$.parser.parse(".optionsAreas");
        //},1000);
    });

    /**
     * 操作按钮处理
     * @param {Object} value
     * @param {Object} row
     * @param {Object} index
     */
    function getOptionsBtn(value, row, index) {
        var btnsHtml = "<span class='optionBtnsArea'>";
        //var doSubmitHtml = '<a href="javascript:void(0)" onclick="doSubmit(\'' + row.id + '\')" class="">提交</a>&nbsp;';
        //var toUpdateHtml = '<a href="javascript:void(0)" onclick="openDataDialog(projectsParamObj,\'' + row.id + '\')" class="">修改</a>&nbsp;';
        //var callBackHtml = '<a href="javascript:void(0)" onclick="doCallback(\'' + row.id + '\')" class="">撤回</a>&nbsp;';
        var infoViewHtml = '<a href="javascript:void(0)" onclick="getProjectDetail(\'' + row.id + '\')" class="">项目详情</a>&nbsp;';
        //var cancelHtml = '<a href="javascript:void(0)" onclick="doCancel(\'' + row.id + '\')" class="">撤销</a>&nbsp;';
        var shotHtml = '<a href="javascript:void(0)" onclick="shot(projectsParamObj,\'' + row.id + '\')" class="">竞价</a>&nbsp;';
        var uploadContractHtml = '<a href="javascript:void(0)" onclick="uploadContract(\'' + row.id + '\')" class="">上传合同</a>&nbsp;';

        btnsHtml += shotHtml;
        btnsHtml += infoViewHtml;

        return btnsHtml + "</span>";
    }


    var btsubmit;//报价投标按钮
    /**
     * 竞价操作
     */
    function shot(paramObj, id) {
        if (id == undefined) {
            id = '';
        }
        var sign = false;
        top.$('#' + paramObj.showDialogId).dialog({
            title: paramObj.addDialogTitle,
            iconCls: 'icon-view',
            width: paramObj.addDialogWidth + 130,
            height: paramObj.addDialogHeight,
            closed: false,
            inline: true,
            cache: false,
            close: afterClosed,
            href: "${ctx}/business/projectmanage/bidder/shotInput?projectId=" + id,
            modal: true,
            extractor: function (data) {
                if ($.trim(data) == "unLogin") {
                    var msn = '' || i18n[''];
                    msn = msn || i18n[data];
                    if (msn != undefined) {
                        top.$.messager.alert('提示', msn, 'info', function () {
                            top.location = '${ctx}/user-login-sys-new/loginPwd';
                        });
                        return '';
                    }
                }
                return data;
            },
            buttons: [{
                text: '提交',
                id: 'btsubmit',
                iconCls: 'icon-ok',
                handler: function () {
                    submitEntity();
                    if (top.$('#' + paramObj.addDataFormId).form('validate')) {//表单校验是否通过
                        btsubmit = $(this).find("span").parent();
                        $(this).find("span").parent().css("display", "none");//隐藏提交按钮
                    }
                }
            },
                {
                    text: '保存',
                    id: 'commitEntityBt',
                    iconCls: 'icon-ok',
                    handler: function () {
                        top.$('#commitEntityBt').linkbutton('disable');
                        saveEntity();
                    }
                }, {
                    text: paramObj.cancelButton,//取消
                    iconCls: 'icon-cancel',
                    handler: function () {
                        top.$('#' + paramObj.showDialogId).dialog('close');
                    }
                }],
            onClose: function () {// 解决IE浏览器中无法移除object标签，导致上传插件的flash无法使用，所有的dialog都会出现问题
                top.$(".uploadify").each(function () {
                    //alert($(this).parent().parent().find(".uploadify").attr("id"));
                    var uploadId = $(this).parent().parent().find(".uploadify").attr("id");
                    //alert("#"+uploadId);
                    top.$("#" + uploadId).uploadify('destroy');//销毁文件上传对象....
                });

                if (top.$('#' + paramObj.showDialogId).find("object").length > 0) {
                    var fileQueue = top.window.document.getElementById("fileQueue");
                    fileQueue.innerHTML = "";
                    fileQueue.parentNode.removeChild(fileQueue);
                }
                afterClosed();
            }
        });
        top.$('#' + paramObj.showDialogId).dialog("center");
    }

    /**保存操作*/
    function saveEntity() {
        debugger;
        $.ajax({
            type: "POST",
            timeout: 20000,
            url: top.$("#addProjectsDataForm").attr("saveaction"),//"${ctx}/business/projectmanage/bidder/saveShot",
            data: top.$('#addProjectsDataForm').serialize(),
            success: function (data, res) {
                if (data == 'success') {
                    top.$.messager.alert("提示", '保存成功', 'info', function () {
                        top.$('#firstLevelDialog').dialog('close');
                        top.$("#uploadify").uploadify('destroy');//销毁文件上传对象....
                        top.$('#listProjectsTable').datagrid('reload');
                    });
                } else if (data == 'nobid') {
                    top.$.messager.alert("提示", '保存成功！', 'info', function () {
                        top.$('#firstLevelDialog').dialog('close');
                        top.$("#uploadify").uploadify('destroy');//销毁文件上传对象....
                        $('#listProjectsTable').datagrid('reload');
                    });
                } else if (data == 'noqualificabid') {
                    top.$.messager.alert('提示', "投标失败！您未缴纳保证金!", 'error', function () {
                        $('#listProjectsTable').datagrid('reload');
                        top.$('#firstLevelDialog').dialog('close');
                    });
                } else if (data == 'noregqualificabid') {
                    top.$.messager.alert('提示', "投标失败！您无此项目类型的投标资格!", 'error', function () {
                        $('#listProjectsTable').datagrid('reload');
                        top.$('#firstLevelDialog').dialog('close');
                    });
                } else if (data == 'atypism') {
                    top.$.messager.alert('提示', "投标失败！银行户名与系统帐户名不一致!", 'error', function () {
                        $('#listProjectsTable').datagrid('reload');
                        top.$('#firstLevelDialog').dialog('close');
                    });
                }
                else {
                    top.$.messager.alert('提示', "保存失败！", 'info');
                    top.$('#commitEntityBt').linkbutton('enable');
                }
            },
            error: function (res) {
                top.$('#commitEntityBt').linkbutton('enable');
            }
        });
    }

    /**
     *提交按钮操作
     */
    function submitEntity() {
        if (top.$('#firstLevelDialog').form('validate')) {//表单校验是否通过
            $.ajax({
                type: "post",
                url: top.$("#addProjectsDataForm").attr("action"),//"${ctx}/business/projectmanage/bidder/doSubmitShot?r="+new Date().getTime(),
                data: top.$("#addProjectsDataForm").serialize(),
                success: function (data) {
                    if (data == "success") {
                        debugger;
                        top.$.messager.alert("提示", '提交成功', 'info', function () {
                            $('#listProjectsTable').datagrid('reload');
                            top.$('#firstLevelDialog').dialog('close');
                        });
                    } else if (data == 'nobid') {
                        debugger;
                        top.$.messager.alert("提示", '提交成功', 'info', function () {
                            $('#listProjectsTable').datagrid('reload');
                            top.$('#firstLevelDialog').dialog('close');
                        });
                    } else if (data == 'nosubmitbid') {
                        top.$.messager.alert('提示', "投标失败！当前时间不能提交，请于开标前30分钟内提交!", 'error', function () {
                            btsubmit.css("display", "inline-block");//显示提交按钮
                        });
                    } else if (data == 'exitbid') {
                        top.$.messager.alert('提示', "投标失败！您已经投过标了!", 'error', function () {
                            $('#listProjectsTable').datagrid('reload');
                            top.$('#firstLevelDialog').dialog('close');
                        });
                    } else if (data == 'noqualificabid') {
                        top.$.messager.alert('提示', "投标失败！您未缴纳保证金!", 'error', function () {
                            $('#listProjectsTable').datagrid('reload');
                            top.$('#firstLevelDialog').dialog('close');
                        });
                    } else if (data == 'noregqualificabid') {
                        top.$.messager.alert('提示', "投标失败！您无此项目类型的投标资格!", 'error', function () {
                            $('#listProjectsTable').datagrid('reload');
                            top.$('#firstLevelDialog').dialog('close');
                        });
                    } else if (data == 'outBudgetAmount') {
                        top.$.messager.alert('提示', "投标失败！当前报价大于预算金额!", 'error', function () {
                            btsubmit.css("display", "inline-block");//显示提交按钮
                        });

                    } else if (data == 'atypism') {
                        top.$.messager.alert('提示', "投标失败！银行户名与系统帐户名不一致!", 'error', function () {
                            $('#listProjectsTable').datagrid('reload');
                            top.$('#firstLevelDialog').dialog('close');
                        });
                    }
                    else {
                        top.$.messager.alert("提示", '提交失败!');
                    }
                },
                error: function (data) {
                    top.$.messager.alert("提示", '提交失败!');
                }
            });
        }
    }


    /**
     *校验中标人是否缴纳履约保证金
     **/
    function uploadContract(id) {
        $.ajax({
            type: "POST",
            timeout: 20000,
            url: "${ctx}/business/projectmanage/public/validBidBond?id=" + id,
            data: {},
            success: function (data) {
                if (data == true) {
                    validBidBond(id);//打开上传合同页面
                } else {
                    top.$.messager.alert('提示', "中标人履约保证金未缴纳，请缴纳后再操作！", 'error');
                }
            },
            error: function (res) {

            }
        });
    }


    /**
     * 上传合同操作
     */
    function validBidBond(id) {
        top.$('#firstLevelDialog').dialog({
            title: "上传合同",
            iconCls: 'icon-view',
            width: '600',
            height: '400',
            closed: false,
            inline: true,
            cache: false,
            href: "${ctx}/business/projectmanage/uploadContract?projectId=" + id,
            modal: true,
            close: afterClosed,
            extractor: function (data) {
                if ($.trim(data) == "unLogin") {
                    var msn = '' || i18n[''];
                    msn = msn || i18n[data];
                    if (msn != undefined) {
                        top.$.messager.alert('提示', msn, 'info', function () {
                            top.location = '${ctx}/user-login-sys-new/loginPwd';
                        });
                        return '';
                    }
                }
                return data;
            },
            buttons: [{
                text: '提交',
                iconCls: 'icon-ok',
                id: 'commitEntityBt',
                handler: function () {
                    if (top.$("#budgetMenuData").val() == '') {
                        top.$.messager.alert('提示', "合同附件不能为空！", 'info', function () {
                        });
                        return;
                    }
                    top.$('#commitEntityBt').linkbutton('disable');
                    if (top.$('#addApproveResonForm').form('validate')) {
                        $.ajax({
                            type: "POST",
                            timeout: 20000,
                            url: "${ctx}/business/projectmanage/doSubmitContract",
                            data: top.$('#addCancelResonForm').serialize(),
                            success: function (data) {
                                if (data == "success") {
                                    top.$.messager.alert("提示", '提交成功', 'info', function () {
                                        $('#listProjectsTable').datagrid('reload');
                                        top.$('#firstLevelDialog').dialog('close');
                                        //top.$("#uploadify").uploadify('destroy');//销毁文件上传对象....
                                    });
                                } else {
                                    top.$.messager.alert('提示', "提交失败！合同上传失败，请重新上传!", 'error');
                                }
                            },
                            error: function (res) {

                            }
                        });
                    }
                }

            }
                , {
                    text: '取消',
                    iconCls: 'icon-cancel',
                    handler: function () {
                        top.$('#firstLevelDialog').dialog('close');
                    }
                }],
            onClose: function () {// 解决IE浏览器中无法移除object标签，导致上传插件的flash无法使用，所有的dialog都会出现问题
                //alert(2);
                top.$("#uploadify").uploadify('destroy');//销毁文件上传对象....
                top.$(".fileQueue").uploadify('destroy');//销毁文件上传对象....
                afterClosed();
            }
        });
        top.$('#firstLevelDialog').dialog("center");
    }


    /**
     *项目详情
     */
    function getProjectDetail(id) {
        top.$('#firstLevelDialog').dialog({
            title: "项目详情",
            iconCls: 'icon-view',
            width: 1000,
            height: 580,
            closed: false,
            inline: true,
            cache: false,
            href: "${ctx}/auction/business/getProjectDetail?projectId=" + id + "&roleId=bidder",
            modal: true,
            extractor: function (data) {
                if ($.trim(data) == "unLogin") {
                    var msn = '' || i18n[''];
                    msn = msn || i18n[data];
                    if (msn != undefined) {
                        top.$.messager.alert('提示', msn, 'info', function () {
                            top.location = '${ctx}/user-login-sys-new/loginPwd';
                        });
                        return '';
                    }
                }
                return data;
            },
            buttons: [{
                text: projectsParamObj.cancelButton,
                iconCls: 'icon-cancel',
                handler: function () {
                    top.$('#firstLevelDialog').dialog('close');
                }
            }]
        });
        top.$('#' + projectsParamObj.showDialogId).dialog("center");
    }


    //关闭
    function afterClosed() {


        // 在弹出对话框内找到Uploadify插件，并隐藏之。
        //top.$.find('.upload').hide();

        // 在弹出对话框内找到Uploadify插件，并隐藏之。
        top.$.find('.upload').hide();

        // 将弹出对话框还原成弹出前的状态，并清空里面的内容。
        top.$('#firstLevelDialog').dialog('destroy').empty();

    }

    /**
     * 上传验收报告
     */
    function receivingReport(id) {
        top.$('#firstLevelDialog').dialog({
            title: "上传验收报告",
            iconCls: 'icon-view',
            width: '600',
            height: '300',
            closed: false,
            inline: true,
            cache: false,
            href: "${ctx}/business/projectmanage/buyer/receivingReport?projectId=" + id,
            modal: true,
            close: afterClosed,
            extractor: function (data) {
                if ($.trim(data) == "unLogin") {
                    var msn = '' || i18n[''];
                    msn = msn || i18n[data];
                    if (msn != undefined) {
                        top.$.messager.alert('提示', msn, 'info', function () {
                            top.location = '${ctx}/user-login-sys-new/loginPwd';
                        });
                        return '';
                    }
                }
                return data;
            },
            buttons: [{
                text: '提交',
                iconCls: 'icon-ok',
                handler: function () {
                    if (top.$("#budgetMenuData").val() == '') {
                        top.$.messager.alert('提示', "报告附件不能为空！", 'info', function () {
                        });
                        return;
                    }
                    top.$('#commitEntityBt').linkbutton('disable');
                    if (top.$('#addApproveResonForm').form('validate')) {
                        $.ajax({
                            type: "POST",
                            timeout: 20000,
                            url: "${ctx}/business/projectmanage/uploadReceivingReport",
                            data: top.$('#addCancelResonForm').serialize(),
                            success: function (data) {
                                if (data == "success") {
                                    top.$.messager.alert("提示", '提交成功', 'info', function () {
                                        $('#listProjectsTable').datagrid('reload');
                                        top.$('#firstLevelDialog').dialog('close');
                                        //top.$("#uploadify").uploadify('destroy');//销毁文件上传对象....
                                    });
                                } else {
                                    top.$.messager.alert('提示', "提交失败！", 'info');
                                }
                            },
                            error: function (res) {

                            }
                        });
                    }
                }

            }
                , {
                    text: '取消',
                    iconCls: 'icon-cancel',
                    handler: function () {
                        top.$('#firstLevelDialog').dialog('close');
                    }
                }],
            onClose: function () {// 解决IE浏览器中无法移除object标签，导致上传插件的flash无法使用，所有的dialog都会出现问题
                //alert(2);
                top.$("#uploadify").uploadify('destroy');//销毁文件上传对象....
                afterClosed();
            }
        });
        top.$('#firstLevelDialog').dialog("center");
    }


    //===============================================================
    /**打印中标通知书**/
    function printWinbidAlert(id) {
        window.open("${ctx}/business/projectmanage/bidder/winbidAlertPrint?projectId=" + id);
    }


    /**
     *投标人投标资格校验
     */
    function bidValidate(paramObj, projectId) {
        //检查是否安装了flash
        var fls = flashChecker();
        if (!fls.f) {
            top.$.messager.alert('提示', "您未安装flash，请安装flash后，再进行投标!", 'error', function () {
                window.open("https://get2.adobe.com/cn/flashplayer/?no_redirect", "_blank");
            });
            return;
        }


        $.ajax({
            type: "POST",
            timeout: 20000,
            url: "${ctx}/business/projectmanage/bidder/bidValidate?projectId=" + projectId,
            success: function (data) {
                if (data == "success") {
                    shot(paramObj, projectId);//投标方法调用
                } else if (data == 'nobid') {
                    top.$.messager.defaults = {ok: "继续", cancel: "放弃"};
                    top.$.messager.confirm('提示', "您单位曾有违规行为，参与须谨慎！", function (data) {
                        if (data) {
                            shot(paramObj, projectId);//投标方法调用
                        }
                    });
                    top.$.messager.defaults = {ok: "确认", cancel: "取消"};
                } else if (data == 'nosubmitbid') {
                    top.$.messager.alert('提示', "投标失败！当前时间不能提交，请于开标前30分钟内提交!", 'error');
                } else if (data == 'exitbid') {
                    top.$.messager.alert('提示', "投标失败！您已经投过标了!", 'error', function () {
                        $('#listProjectsTable').datagrid('reload');
                        top.$('#firstLevelDialog').dialog('close');
                    });
                } else if (data == 'noqualificabid') {
                    top.$.messager.alert('提示', "投标失败！您未缴纳保证金!", 'error', function () {
                        $('#listProjectsTable').datagrid('reload');
                        top.$('#firstLevelDialog').dialog('close');
                    });
                } else if (data == 'noregqualificabid') {
                    top.$.messager.alert('提示', "投标失败！您无此项目类型的投标资格!", 'error', function () {
                        $('#listProjectsTable').datagrid('reload');
                        top.$('#firstLevelDialog').dialog('close');
                    });
                } else if (data == 'atypism') {
                    top.$.messager.alert('提示', "投标失败！银行户名与系统帐户名不一致!", 'error', function () {
                        $('#listProjectsTable').datagrid('reload');
                        top.$('#firstLevelDialog').dialog('close');
                    });
                } else if (data == "sealupNobid") {
                    top.$.messager.alert('提示', "投标失败！封存用户不能投标!", 'error', function () {
                        $('#listProjectsTable').datagrid('reload');
                        top.$('#firstLevelDialog').dialog('close');
                    });
                }
                else {
                    top.$.messager.alert("提示", '提交失败!');
                }
            },
            error: function (res) {

            }
        });
    }

    /**打印验收报告*/
    function printReceivinReport(id) {
        window.open("${ctx}/business/projectmanage/printReceivinReport?projectId=" + id);
    }

    /**打印不评标项目验收报告*/
    function printNBReceivinReport(id) {
        window.open("${ctx}/business/projectNb/printReceivinReport?projectId=" + id + "&isShow=true");
    }

    /**
     *投标人撤销投标
     */
    function cancelShot(id) {
        top.$.messager.confirm('提示', "您确认要撤销投标吗！", function (data) {
            if (data) {
                $.ajax({
                    type: "POST",
                    timeout: 20000,
                    url: "${ctx}/business/projectmanage/bidder/cancelShot?projectId=" + id,
                    success: function (data) {
                        if (data == "success") {
                            top.$.messager.alert("提示", '撤销成功', 'info', function () {
                                $('#listProjectsTable').datagrid('reload');
                                top.$('#firstLevelDialog').dialog('close');
                                //top.$("#uploadify").uploadify('destroy');//销毁文件上传对象....
                            });
                        } else {
                            top.$.messager.alert('提示', "撤销失败！", 'error');
                            $('#listProjectsTable').datagrid('reload');
                            top.$('#firstLevelDialog').dialog('close');
                        }
                    },
                    error: function (res) {
                        $.messager.alert('提示', i18n.requestError, 'error');
                    }
                });
            }
        });
    }

    /**打印不评标项目中标通知书**/
    function printNBWinbidAlert(id) {
        window.open("${ctx}/business/projectNb/printWinbidAlert?projectId=" + id + "&isShow=true");
    }
</script>


<script type="text/javascript">

    var websocket = null;
    var myUid = '${user.id}';
    var connectLink = true;//是否重连

    // 连接服务端
    function connect(code) {
        // 创建websocket
        websocket = new WebSocket("ws://" + document.domain + ":" + window.location.port + "${ctx}/AuctionWebSocket/${sessionId}/" + code);
        // 当socket连接打开时，输入用户名
        websocket.onopen = function () {
            console.log("websocket握手成功!");
        };
        // 当有消息时根据消息类型显示不同信息
        websocket.onmessage = onmessage;
        websocket.onclose = function () {
            websocket = null;
            console.log("连接关闭，定时重连");
            if (connectLink == true) {
                top.$("#manual_but").attr({"disabled": "disabled"}).unbind("click").val("正在链接服务器");
                connect(code);
            }
            else {
                top.$("#manual_but").attr({"disabled": "disabled"}).unbind("click");
            }
        };
        websocket.onerror = function () {
            console.log("出现错误");
        };
    }

    // 服务端发来消息时
    function onmessage(e) {
        var data = null;
        try {
            data = JSON.parse(e.data);
        }
        catch (err) {
            top.$.messager.alert("提示", e.data, "error");
            connectLink = false;
            return;
        }
        switch (data['type']) {
            case 'bid':             // 价格变动
                bidChange(data);
                break;
            case 'OK':
                top.$("#manual_but").removeAttr("disabled").on("click", auctionBid).val("出  价");
                break;
            case 'userFlag':        // 用户封存
                top.$("#manual_but").attr({"disabled": "disabled"}).unbind("click").val("封存用户");
                top.$.messager.alert("提示", data.message, "error");
                break;
            case 'stop':            // 用户禁拍
                top.$("#manual_but").attr({"disabled": "disabled"}).unbind("click").val("禁止竞拍");
                top.$.messager.alert("提示", data.message, "error");
                break;
            case 'entryAble':       // 没有报名
                top.$("#manual_but").attr({"disabled": "disabled"}).unbind("click").val("尚未报名");
                top.$.messager.alert("提示", data.message, "error");
                break;
            case 'deposit':         // 是否交了保证金
                if (data.errorCode == -1) {
                    top.$("#manual_but").attr({"disabled": "disabled"}).unbind("click").val("保证金异常");
                    top.$.messager.alert("提示", "您当前保证金校验异常,暂不能参与竞拍!", "error");
                } else if (data.errorCode == 0) {
                    top.$("#manual_but").attr({"disabled": "disabled"}).unbind("click").val("未交保证金");
                    top.$.messager.alert("提示", "您当前未缴纳保证金校验,暂不能参与竞拍!", "error");
                } else if (data.errorCode == 5) {
                    top.$("#manual_but").attr({"disabled": "disabled"}).unbind("click").val("账户异常");
                    top.$.messager.alert("提示", "您当前银行户名或开户行与系统帐户名或开户行不一致,暂不能参与竞拍!", "error");
                } else {
                    top.$("#manual_but").attr({"disabled": "disabled"}).unbind("click").val("保证金错误");
                    top.$.messager.alert("提示", "您当前保证金校验出错 " + data.errorCode + " ,暂不能参与竞拍!", "error");
                }
                break;
            case 'error':
                if (data.errorCode == -1) {
                    top.$.messager.alert("提示", data.message, "error", function () {
                        top.location = '${ctx}/user-login-sys-new/loginPwd';
                    });
                }
                else if (data.errorCode == -2) {
                    top.$.messager.alert("提示", data.message, "error", function () {
                        top.$('#auctionInfoDialog').dialog("close", false);
                        window.location = window.location;
                    });
                }
                else if (data.errorCode == 0) {
                    top.$.messager.alert("提示", data.message, "error");
                    break;
                }
                else {
                    top.$.messager.alert("提示", data.message, "error");
                }
                connectLink = false;
                break;
        }
    }

    // 更新页面信息
    function bidChange(data) {
        // 当前价
        var nowPrice = data.nowprice;
        top.$('#nowprice').text(nowPrice);// 当前价
        if (data.biddrId != myUid) {
            top.$('#my_record tr.lingxian').removeClass('lingxian');
        }
        else {
            addMyBidRecord(data.biddrId, data.nowprice, data.bidderTime);
        }
        addBidRecord(data.biddrId, data.bidderName, data.nowprice, data.bidderTime);

        //重新计算时间
        biddingEnd(data.endtime, data.bidderTime, data.code);
    }

    //向服务器发送消息
    function sendMsg(msg) {
        if (websocket == null) {
            return false;
        }
        websocket.send(msg);
    }

    //监听窗口关闭事件，当窗口关闭时，主动去关闭websocket连接，防止连接还没断开就关闭窗口，server端会抛异常。
    window.onbeforeunload = function () {
        closeWebSocket();
    }

    //关闭WebSocket连接
    function closeWebSocket() {
        connectLink = false;
        if (websocket == null) {
            return;
        }
        websocket.close();
        websocket = null;
    }

    //时钟句柄
    var endDowntimer = 0;

    // 倒计时
    function endDown(etime, ntime, boxobj, day_elem, hour_elem, minute_elem, second_elem, msec_elem, callback) {
        var now_time = new Date(ntime * 1);
        var end_time = new Date(etime * 1);
        var native_time = new Date().getTime(); //本地时间
        var now_cha = now_time - native_time; //服务器和本地时间差
        var native_end_time = end_time - now_cha; //本地结束时间
        var sys_second = 0;
        endDowntimer = setInterval(function () {
            sys_second = (native_end_time - new Date().getTime()) / 100; //本地结束剩余时间
            //console.log(sys_second);
            if (sys_second > 0) {
                sys_second -= 1;
                var day = Math.floor((sys_second / 36000) / 24);
                var hour = Math.floor((sys_second / 36000) % 24);
                var minute = Math.floor((sys_second / 600) % 60);
                var second = Math.floor((sys_second / 10) % 60);
                var msec = Math.floor(sys_second % 10); //毫秒
                top.$(day_elem).text(day);//计算天
                top.$(hour_elem).text(hour < 10 ? "0" + hour : hour);//计算小时
                top.$(minute_elem).text(minute < 10 ? "0" + minute : minute);//计算分
                top.$(second_elem).text(second < 10 ? "0" + second : second);// 计算秒
                top.$(msec_elem).text(msec);// 计算秒的1/10
                native_time = new Date().getTime();
            } else {
                clearInterval(endDowntimer);//关掉定时器
                callback();
            }
        }, 100);
    }

    //获取服务器时间
    function getServerTime() {
        //获取新闻类型 生成菜单
        return $.ajax({
            type: "post",
            async: false,//同步请求
            cache: false,
            url: "${ctx}/auctionBid/business/getNowTime"
        }).responseText;
    }

    //添加出价记录
    function addBidRecord(biddrId, bidderName, bidderPrice, bidderTime) {
        var html = '<tr uid="' + biddrId + '" class="lingxian">';
        html += '<td><div class="bidlistico"></div></td>';
        html += '<td><span class="on_over" style="width: 60px;">' + bidderName + '</span></td>';
        html += '<td>' + bidderPrice + '</td>';
        //文档
        //http://momentjs.cn/docs/#/customization/
        html += '<td>' + moment(bidderTime).format("YYYY-MM-DD HH:mm:ss.SSS") + '</td>';
        var tr = top.$("#bid_record tbody tr");
        if (tr.length >= 11) {
            tr.last().remove();
        }
        tr.filter(".lingxian").removeClass("lingxian");
        tr.first().after(html);
        var count = top.$("#bidcount").text();
        top.$("#bidcount").text(++count);
    }

    //添加我的出价记录
    function addMyBidRecord(biddrId, bidderPrice, bidderTime) {
        var html = '<tr uid="' + biddrId + '" class="lingxian">';
        html += '<td><div class="bidlistico"></div></td>';
        html += '<td>' + bidderPrice + '</td>';
        html += '<td>' + moment(bidderTime).format("YYYY-MM-DD HH:mm:ss.SSS") + '</td>';
        var tr = top.$("#my_record tbody tr");
        if (tr.length >= 11) {
            top.$("#recordB").css({"overflow-y": "auto"});
            top.$("#recordB .tip").css({'position': 'static', "width": "auto"});
        }
        tr.filter(".lingxian").removeClass("lingxian");
        tr.first().after(html);
        top.$("#mycount").text(tr.length);
    }

    //出价 单击事件
    function auctionBid() {
        var uid = top.$("#bid_record tr.lingxian").attr("uid");
        //console.log(myUid);
        if (uid != undefined && uid == myUid) {
            top.$.messager.alert("提示", "您当前已是最高价,无需重复报价!");
            return;
        }
        var price = top.$("#selectPrice").val();
        if (price <= 0) {
            top.$.messager.alert("提示", "还未选择报价,请选择报价!");
            return;
        }
        price = parseFloat(price) + parseFloat(top.$("#nowprice").text());
        var params = {};
        params.type = "bid";
        params.message = "报价"
        params.price = parseFloat(price).toFixed(2);
        top.$.messager.confirm('确认', '您确认想以[' + params.price + ']的价格,进行竞拍吗？', function (r) {
            if (r) {
                //top.$("#manual_but").attr({"disabled": "disabled"}).val("出价中...");
                sendMsg(JSON.stringify(params));
            }
        });
    }

    //获取竞价的拟定中标人
    function getProposedAuctionWinner(code) {
        return $.ajax({
            type: "post",
            async: false,//同步请求
            cache: false,
            data: {'code': code},
            url: "${ctx}/auctionBid/business/getProposedAuctionWinner"
        }).responseText;
    }

    //中标结果
    function WinnerReslut(code, isShowAler) {
        top.$("#manual_but").attr({"disabled": "disabled"}).unbind("click").val("竞拍结束");
        top.$("#bidTimeStatus").css({"color": "#999"}).html("竞拍结束");
        top.$("#onBidtime").hide();
        top.$(".ontab_con tr.lingxian").attr("class", "chengjiao");
        var winner = getProposedAuctionWinner(code);
        if (winner == null || winner.length <= 2) {
            if (isShowAler == true) {
                top.$.messager.alert('提示', "尚未有人出价，流拍!", 'error');
            }
            top.$("#bidTimeStatus").css({"color": "#999"}).html("拟定竞拍结果: <span style='color:red'>流拍</span>");
            return "";
        }
        winner = JSON.parse(winner);
        var userName = winner.bidderName;
        winner.bidderPrice = parseFloat(winner.bidderPrice).toFixed(2);
        if (winner.biddrId == myUid) {
            userName = '您';
        }
        var msg = '恭喜' + userName + '以[' + winner.bidderPrice + ']元，中标!';
        var msghtml = "<span style='color:#333'>恭喜<span style='color:red'>" + winner.bidderName + "</span>以<span style='color:red'>" + winner.bidderPrice + "</span>元，中标</span>";
        top.$("#bidTimeStatus").css({"color": "#999"}).html("拟定竞拍结果: " + msghtml);
        if (isShowAler == true) {
            top.$.messager.alert('提示', msg);
        }
        return msg;
    }

    //竞拍结束倒计时
    function biddingEnd(endTime, nowTime, code) {
        //关闭倒计时
        clearInterval(endDowntimer);
        endDown(endTime, nowTime, ".onBidtime", ".onBidtime .day", ".onBidtime .hour", ".onBidtime .minute", ".onBidtime .second", ".onBidtime .msec", function () {
            WinnerReslut(code, true);
            closeWebSocket();//断开链接
        });
    }

    //开始竞拍
    function startBidding(endTime, nowTime, code, entryAbleInfo) {
        // if (entryAbleInfo.userFlag == 1) {
        //     //用户不存在
        //     top.$("#manual_but").attr({"disabled": "disabled"}).unbind("click").val("用户不存在");
        // } else if (nowTime < entryAbleInfo.forbidEndDate) {
        //     //禁拍用户
        //     top.$("#manual_but").attr({"disabled": "disabled"}).unbind("click").val("禁止竞拍");
        // }
        // else if (entryAbleInfo.userFlag == 2) {
        //     //封存用户
        //     top.$("#manual_but").attr({"disabled": "disabled"}).unbind("click").val("封存用户");
        // }
        // else if (entryAbleInfo.isEntryAble == false) {
        //     top.$("#manual_but").attr({"disabled": "disabled"}).unbind("click").val("尚未报名");
        // }
        // else if (entryAbleInfo.depositStatus == 0) {
        //     //未交保证金
        //     top.$("#manual_but").attr({"disabled": "disabled"}).unbind("click").val("未交保证金");
        // }
        // else if (entryAbleInfo.depositStatus == 5) {
        //     //银行户名或开户行与系统帐户名或开户行不一致
        //     top.$("#manual_but").attr({"disabled": "disabled"}).unbind("click").val("账户异常");
        // }
        // else if (entryAbleInfo.depositStatus == -1) {
        //     //校验保证金失败
        //     top.$("#manual_but").attr({"disabled": "disabled"}).unbind("click").val("保证金异常");
        // }
        // else {
        //     top.$("#manual_but").attr({"disabled": "disabled"}).unbind("click").val("正在链接服务器");
        //     //top.$("#manual_but").removeAttr("disabled").on("click", auctionBid).val("出  价");
        // }

        top.$("#manual_but").attr({"disabled": "disabled"}).unbind("click").val("正在链接服务器");
        top.$("#bidTimeStatus").removeAttr("style").html("正在拍卖<span class='zt'>距结束</span>");
        biddingEnd(endTime, nowTime, code);

        connect(code);
        // if (entryAbleInfo.isEntryAble == true && entryAbleInfo.depositStatus == 1 && entryAbleInfo.userFlag == 0) {
        //     connect(code);
        // }
    }

    //判断是否已经通过报名和已交保证金
    function getEntryAbleAndDeposit(code) {
        return $.ajax({
            type: "post",
            async: false,//同步请求
            cache: false,
            data: {'code': code},
            url: "${ctx}/auctionBid/business/getEntryAbleAndDeposit"
        }).responseText;
    }

    //获取项目的开始竞拍时间和截止竞拍时间
    function getAuctionStartTimeAndEndTime(code) {
        return $.ajax({
            type: "post",
            async: false,//同步请求
            cache: false,
            data: {'code': code},
            url: "${ctx}/auctionBid/business/getAuctionStartTimeAndEndTime"
        }).responseText;
    }

    /**
     *竞拍详情
     */
    function auctionInfo(code) {
        if (typeof WebSocket == 'undefined') {
            $.messager.alert("提示", "请使用IE9以上版本或360浏览器极速模式参加竞拍。");
            return;
        }
        top.$('#auctionInfoDialog').dialog({
            title: "竞拍详情",
            iconCls: 'icon-view',
            width: 1000,
            height: 580,
            closed: false,
            inline: true,
            cache: false,
            href: "${ctx}/auctionBid/business/auction?code=" + code,
            modal: true,
            extractor: function (data) {
                if ($.trim(data) == "unLogin") {
                    var msn = '' || i18n[''];
                    msn = msn || i18n[data];
                    if (msn != undefined) {
                        top.$.messager.alert('提示', msn, 'info', function () {
                            top.location = '${ctx}/user-login-sys-new/loginPwd';
                        });
                        return '';
                    }
                }
                return data;
            },
            queryParams: {'checksysno': "dasdasd"},
            onBeforeClose: function () {
                closeWebSocket();
                clearInterval(endDowntimer);//关掉定时器
            },
            onLoad: function () {
                var entryAbleInfo = JSON.parse(getEntryAbleAndDeposit(code));//报名和报价信息
                var auctionTime = JSON.parse(getAuctionStartTimeAndEndTime(code));//获取项目的开始竞拍时间和截止竞拍时间
                var nowTime = getServerTime();
                //var nowTime = 1511511720000;
                var endTime = auctionTime.endTime;
                var startTime = auctionTime.startTime;
                //var endTime = 1511511726000;
                //var startTime = 1511511723000;
                connectLink = true;
                if (nowTime <= startTime) {
                    if (entryAbleInfo.userFlag == 1) {
                        //用户不存在
                        top.$("#manual_but").attr({"disabled": "disabled"}).unbind("click").val("用户不存在");
                    } else if (nowTime < entryAbleInfo.forbidEndDate) {
                        //禁拍用户
                        top.$("#manual_but").attr({"disabled": "disabled"}).unbind("click").val("禁止竞拍");
                        top.$.messager.alert("提示", "您当前用户状态是禁拍状态,不能参与竞拍!", "error");
                    }
                    else if (entryAbleInfo.userFlag == 2) {
                        //封存用户
                        top.$("#manual_but").attr({"disabled": "disabled"}).unbind("click").val("封存用户");
                        top.$.messager.alert("提示", "您当前用户状态是封存状态,不能参与竞拍!", "error");
                    }
                    else if (entryAbleInfo.isEntryAble == false) {
                        top.$("#manual_but").attr({"disabled": "disabled"}).unbind("click").val("尚未报名");
                        top.$.messager.alert("提示", "您当前没有通过报名,不能参与竞拍!", "error");
                    }
                    else if (entryAbleInfo.depositStatus == 0) {
                        //未交保证金
                        top.$("#manual_but").attr({"disabled": "disabled"}).unbind("click").val("未交保证金");
                        top.$.messager.alert("提示", "您当前未缴纳保证金校验,暂不能参与竞拍!", "error");
                    }
                    else if (entryAbleInfo.depositStatus == 5) {
                        //银行户名或开户行与系统帐户名或开户行不一致
                        top.$("#manual_but").attr({"disabled": "disabled"}).unbind("click").val("账户异常");
                        top.$.messager.alert("提示", "您当前银行户名或开户行与系统帐户名或开户行不一致,暂不能参与竞拍!", "error");
                    }
                    else if (entryAbleInfo.depositStatus == -1) {
                        //校验保证金失败
                        top.$("#manual_but").attr({"disabled": "disabled"}).unbind("click").val("保证金异常");
                        top.$.messager.alert("提示", "您当前保证金校验异常,暂不能参与竞拍!", "error");
                    } else {
                        top.$("#manual_but").attr({"disabled": "disabled"}).unbind("click").val("尚未开始");
                    }

                    //尚未开始的倒计时
                    top.$("#bidTimeStatus").css({"color": "#999"}).html("尚未开始<span class='zt'>距离开拍仅剩</span>");
                    endDown(startTime, nowTime, ".onBidtime", ".onBidtime .day", ".onBidtime .hour", ".onBidtime .minute", ".onBidtime .second", ".onBidtime .msec", function () {
                        auctionTime = JSON.parse(getAuctionStartTimeAndEndTime(code));//获取项目的开始竞拍时间和截止竞拍时间
                        nowTime = getServerTime();
                        endTime = auctionTime.endTime;
                        startTime = auctionTime.startTime;
//                        nowTime = 1511511720000;
//                        endTime = 1511512836000;//获取竞拍结束时间
                        //console.log("endTime " + endTime);
                        //console.log("nowTime " + nowTime);
                        startBidding(endTime, nowTime, code, entryAbleInfo);
                    });
                } else if (nowTime <= endTime) {
                    startBidding(endTime, nowTime, code, entryAbleInfo);
                }
                else {
                    WinnerReslut(code, false);
                }
            },
            buttons: [{
                text: projectsParamObj.cancelButton,
                iconCls: 'icon-cancel',
                handler: function () {
                    top.$('#auctionInfoDialog').dialog('close');
                }
            }]
        });
        top.$('#' + projectsParamObj.auctionInfoDialogId).dialog("center");
    }

    /**打印中标通知书**/
    function viewPrintWinbidAlert(id) {
        window.open("${ctx}/auctionBid/business/viewPrintWinbidAlert?projectId=" + id + "&isShow=false");
    }

    //校验时间格式
    function RQcheck(RQ) {
        var date = RQ;
        var result = date.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
        if (result == null)
            return false;
        var d = new Date(result[1], result[3] - 1, result[4]);
        return (d.getFullYear() == result[1] && (d.getMonth() + 1) == result[3] && d.getDate() == result[4]);
    }

    //时间比较
    function compareDate(date1, oDate2) {
        var oDate1 = new Date(date1);
        if (oDate1.getTime() > oDate2.getTime()) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 上传合同操作
     */
    function uploadAuctionContract(id) {
        top.$('#firstLevelDialog').dialog({
            title: "上传合同",
            iconCls: 'icon-view',
            width: '600',
            height: '400',
            closed: false,
            inline: true,
            cache: false,
            href: "${ctx}/auctionBid/business/owner/uploadAuctionContract?projectId=" + id,
            modal: true,
            close: afterClosed,
            extractor: function (data) {
                if ($.trim(data) == "unLogin") {
                    var msn = '' || i18n[''];
                    msn = msn || i18n[data];
                    if (msn != undefined) {
                        top.$.messager.alert('提示', msn, 'info', function () {
                            top.location = '${ctx}/user-login-sys-new/loginPwd';
                        });
                        return '';
                    }
                }
                return data;
            },
            buttons: [{
                text: '提交',
                iconCls: 'icon-ok',
                id: 'commitEntityBt',
                handler: function () {
                    var resDataListCount = top.$("#resDataList div").length;//合同附件已记录的附件
                    var uploadedCount = top.$("#fileQueue13 .cancel").length;//合同附件以保存但为绑定的附件
                    var isBackTime = top.$("#isBackTime");

                    //判断是否是中心托管项目
                    if (isBackTime.is(":hidden") == false) {
                        var backTime = $.trim(top.$('#backTime').datebox('getValue'));
                        if (backTime.length <= 0) {
                            top.$.messager.alert('提示', "履约保证金退还时间,不能为空！", 'info', function () {
                            });
                            return;
                        }
                        if (RQcheck(backTime) == false) {
                            top.$.messager.alert('提示', "履约保证金退还时间,时间格式不正确！", 'info', function () {
                            });
                            return;
                        }
                        if (compareDate(backTime, new Date()) == false) {
                            top.$.messager.alert('提示', "履约保证金退还时间,不能小于当前时间！", 'info', function () {
                            });
                            return;
                        }
                    }

                    if (resDataListCount <= 0 && uploadedCount <= 0) {
                        top.$.messager.alert('提示', "合同附件不能为空！", 'info', function () {
                        });
                        return;
                    }
                    var otherResDataListCount = top.$("#otherResDataList div").length;//合同附件已记录的附件
                    var otherUploadedCount = top.$("#fileQueue14 .cancel").length;//合同附件以保存但为绑定的附件
                    if (otherResDataListCount <= 0 && otherUploadedCount <= 0) {
                        top.$.messager.alert('提示', "中标通知书附件不能为空！", 'info', function () {
                        });
                        return;
                    }
                    top.$('#commitEntityBt').linkbutton('disable');
                    if (top.$('#addApproveResonForm').form('validate')) {
                        $.ajax({
                            type: "POST",
                            timeout: 20000,
                            url: "${ctx}/auctionBid/business/owner/doSubmitContract",
                            data: top.$('#addCancelResonForm').serialize(),
                            success: function (data) {
                                if (data == "success") {
                                    top.$.messager.alert("提示", '提交成功', 'info', function () {
                                        $('#listProjectsTable').datagrid('reload');
                                        top.$('#firstLevelDialog').dialog('close');
                                        //top.$("#uploadify").uploadify('destroy');//销毁文件上传对象....
                                    });
                                } else if (data == "noExecuteDeposit") {
                                    top.$.messager.alert('提示', "提交失败！未缴纳履约保证金！", 'info');
                                } else {
                                    top.$.messager.alert('提示', "提交失败！合同上传失败，请重新上传！", 'info');
                                }
                            },
                            error: function (res) {

                            }
                        });
                    }
                }

            }
                , {
                    text: '取消',
                    iconCls: 'icon-cancel',
                    handler: function () {
                        top.$('#firstLevelDialog').dialog('close');
                    }
                }],
            onClose: function () {// 解决IE浏览器中无法移除object标签，导致上传插件的flash无法使用，所有的dialog都会出现问题
                //alert(2);
                top.$("#uploadify").uploadify('destroy');//销毁文件上传对象....
                afterClosed();
            }
        });
        top.$('#firstLevelDialog').dialog("center");
    }

    /**
     *校验中标人是否缴纳竞价的履约保证金
     **/
    function validAuctionBidBond(id) {
        $.ajax({
            type: "POST",
            timeout: 20000,
            url: "${ctx}/auctionBid/business/validBidBond?auctionInfoId=" + id,
            data: {},
            success: function (data) {
                if (data == true) {
                    uploadAuctionContract(id);//打开上传合同页面
                } else {
                    top.$.messager.alert('提示', "中标人履约保证金未缴纳，请缴纳后再操作！", 'error');
                }
            },
            error: function (res) {

            }
        });
    }

    function signProject(id) {
        top.$('#firstLevelDialog').dialog({
            title: "报名",
            iconCls: 'icon-role-menu',
            width: 450,
            height: 300,
            closed: false,
            inline: true,
            cache: false,
            href: "${ctx}/auction/business/regAudit/uploadPage?id=" + id,
            modal: true,
            buttons: [{
                text: '提交',
                id: 'saveEntityBt',
                iconCls: 'icon-ok',
                handler: function () {
                    debugger
                    var uploadify = top.$("#uploadify").val();
                    if (uploadify == "") {
                        top.$.messager.alert('提示', "请选择上传报名材料！", 'info');
                    } else {
                        $.ajax({
                            type: "POST",
                            timeout: 20000,
                            url: "${ctx}/auction/business/regAudit/save?uploadify=" + uploadify,
                            data: top.$('#signForm').serialize(),
                            success: function (data) {
                                if (data == "success") {
                                    top.$.messager.alert('提示', '报名成功', 'success', function () {
                                        $('#listProjectsTable').datagrid('reload');
                                        top.$('#firstLevelDialog').dialog('close');
                                    });
                                } else if (data == "overtime") {
                                    top.$.messager.alert('提示', '竞拍已开始，报名超时！', 'unSuccess', function () {
                                        $('#listProjectsTable').datagrid('reload');
                                        top.$('#firstLevelDialog').dialog('close');
                                    });
                                } else {
                                    top.$.messager.alert('提示', '报名已成功,请勿重复报名', 'unSuccess', function () {
                                        $('#listProjectsTable').datagrid('reload');
                                        top.$('#firstLevelDialog').dialog('close');
                                    });
                                }

                            },
                            error: function () {
                                top.$.messager.alert('提示', i18n.requestError, 'error');
                            }
                        });
                    }
                }
            }, {
                text: '取消',
                iconCls: 'icon-cancel',
                handler: function () {
                    top.$('#firstLevelDialog').dialog('close');
                }
            }],
            onClose: function () {// 解决IE浏览器中无法移除object标签，导致上传插件的flash无法使用，所有的dialog都会出现问题
                top.$("#uploadify").uploadify('destroy');//销毁文件上传对象....
                afterClosed();
            }
        });
        top.$('#firstLevelDialog').dialog("center");
    }

    function signStatus(id) {
        //审核不通过
        top.$('#firstLevelDialog').dialog({
            title: "审核状态",
            iconCls: 'icon-view',
            width: 360,
            height: 250,
            closed: false,
            inline: true,
            cache: false,
            href: '${ctx}/auction/business/regAudit/signStatus?id=' + id,
            modal: true,
            extractor: function (data) {
                if ($.trim(data) == "unLogin") {
                    var msn = '' || i18n[''];
                    msn = msn || i18n[data];
                    if (msn != undefined) {
                        top.$.messager.alert('提示', msn, 'info', function () {
                            top.location = '${ctx}/user-login-sys-new/loginPwd';
                        });
                        return '';
                    }
                }
                return data;
            },
            buttons: [{
                text: '取消',
                iconCls: 'icon-cancel',
                handler: function () {
                    top.$('#firstLevelDialog').dialog('close');
                }
            }]
        });

    }

</script>